var isMale = true; 
// 默认头像为男生
 var isPaused = false; 
// 默认计时器未暂停
var timer; 
// 定时器 
var counter = 0; 
// 计时器初始值
 var is24Hour = false; 
// 默认为12小时时钟

window.onload = function() { 
        clockStart();
    }

function changeAvatar() {
    if (isMale) { 
        document.getElementById("avatar").src = "head2.png";
        isMale = false;
} else { 
    document.getElementById("avatar").src = "head1.png"; 
    isMale = true;
}
    alert("当前头像性别：" + (isMale ? "男生" : "女生") + "\n当前计时器数字：" + counter);
}

function clockStart() {
    var today = new Date();
    var h = today.getHours();
    var m = today.getMinutes();
    var s = today.getSeconds();
    if (!is24Hour) {
        var ampm = (h >= 12) ? "pm" : "am";
        h = (h % 12) || 12; h = h < 10 ? "0" + h : h; 
        document.getElementById("txt_clock").innerHTML = h + ":" + (m < 10 ? "0" + m : m) + ":" + (s < 10 ? "0" + s : s) + " " + ampm; 
    } else {
        document.getElementById("txt_clock").innerHTML = (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":" + (s < 10 ? "0" + s : s);
     } 
    t = setTimeout("clockStart()", 500);
 }

function timerStart() { 
    timer = setInterval(function() { 
        if (!isPaused) {
             document.getElementById("timer_txt").value = counter++; 
                if (counter === 15) {
                     alert("当前头像性别：" + (isMale ? "男生" : "女生") + "\n当前时间：" + document.getElementById("txt_clock").innerHTML);
             }
         }
        }, 1000); }

function timerStop() { 
    clearInterval(timer);
    counter = 0;
    document.getElementById("timer_txt").value = counter; }

function timerPause() {
    isPaused = true; 
    }

function timerContinue() {
    isPaused = false;
    }
